package com.online.jta.util.db;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * Spring多数据源选择器
 * 
 * @author tongyufu
 *
 */
public class RoutingDataSource extends AbstractRoutingDataSource {

    public static final String MYSQL = "mysql";
    public static final String ORACLE = "oracle";
    private static final ThreadLocal<String> dataSourceKey = new InheritableThreadLocal<String>();

    public static void setDataSourceKey(String dataSource) {
        dataSourceKey.set(dataSource);
    }
    
    public static String getDataSourceKey() {
        return dataSourceKey.get();
    }

    @Override
    protected Object determineCurrentLookupKey() {
        return dataSourceKey.get();
    }

}
